<?php
header("Content-type: text/html; charset=utf-8");
class payonline{
	public $payno; //订单号
	public $subject; //订单名称
	public $body; //订单描述
	public $payment; //支付金额
	public $payaccount; //支付账户
	public $mode; //支付模式 0 手动组织form表单 1自动提交
	public $type; //0 支付宝 1 网银 2 快钱 3手机支付
	function __construct($pay){
		$this->payno=$pay['payno'];
		$this->subject=$pay['subject'];
		$this->subject=$pay['subject'];
		$this->subject=str_replace("'","",$this->subject);
		$this->subject=str_replace("\"","",$this->subject);
		$this->body=$pay['body'];
		$this->body=$pay['body'];
		$this->body=str_replace("'","",$this->body);
		$this->body=str_replace("\"","",$this->body);
		$this->payment=$pay['payment'];
		$this->payaccount=$pay['payaccount'];

		if(!isset($pay['mode'])){
			$this->mode=0;
		}else{
			$this->mode=$pay['mode'];
		}
	    $this->alipay();
	}
	function alipay(){
		require_once("api/alipay_mobile/config.php");
		require_once("api/alipay_mobile/wappay/service/AlipayTradeService.php");
		require_once("api/alipay_mobile/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php");
		/**************************请求参数**************************/
		//商户订单号，商户网站订单系统中唯一订单号，必填
		$out_trade_no = $this->payno;

		//订单名称，必填
		$subject = $this->subject;

		//付款金额，必填
		$total_amount = $this->payment;

		//商品描述，可空
		$body = $this->body;

		//超时时间
		$timeout_express="5m";
		$payRequestBuilder = new AlipayTradeWapPayContentBuilder();
		$payRequestBuilder->setBody($body);
		$payRequestBuilder->setSubject($subject);
		$payRequestBuilder->setOutTradeNo($out_trade_no);
		$payRequestBuilder->setTotalAmount($total_amount);
		$payRequestBuilder->setTimeExpress($timeout_express);

		$payResponse = new AlipayTradeService($config);
		$result=$payResponse->wapPay($payRequestBuilder,$config['return_url'],$config['notify_url'],$this->mode);
	}

}
//$pay=array("subject"=>"这是订单标题","body"=>"这是个订单描述","payment"=>0.01,"orderno"=>"ON200412230002","type"=>0,"payaccount"=>'',"mode"=>1);
//$pay=array("subject" => "泰泰快购 | 最快的送货速度  最佳的用户体验  最实惠的价格|1分钱补差价","body" => "泰泰快购 | 最快的送货速度  最佳的用户体验  最实惠的价格|1分钱补差价","payment" =>0.01,"orderno" => "TRB806203526887747","type" => "0","mode" =>" 1");
//new payonline($pay);
?>